package saucaca.fragment;

import saucaca.CustomView.PagerSlidingTabStrip;
import saucaca.Object.HomeData;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lemon.kenhnhacvn.MainActivity;
import com.lemon.kenhnhacvn.R;


public class BXHfragment extends Fragment {
	String TAG = LocalListFragment.class.getSimpleName();
	MainActivity mActivity;
	ViewPager viewPager;
	OfflineTabPageAdapter TabAdapter;
	String areaCode="";
	String week="";
	private PagerSlidingTabStrip tabs;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mActivity = (MainActivity) getActivity();
	}

	@SuppressLint("NewApi")
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//		getActivity().getActionBar().hide();
		View view = inflater.inflate(R.layout.viewpager_tabstrip, container, false);
		findViewById(view);
		TabAdapter = new OfflineTabPageAdapter(getChildFragmentManager());
		final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
		viewPager.setPageMargin(pageMargin);
		viewPager.setAdapter(TabAdapter);
		viewPager.setCurrentItem(0);
		tabs.setViewPager(viewPager);
		mActivity.myActionBar.setMenu(R.string.menu_bxh, false, true);
		return view;
	}
	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		if(!hidden)
			mActivity.myActionBar.setMenu(R.string.menu_bxh, false, true);
	}

	private void findViewById(View view) {
		viewPager = (ViewPager) view.findViewById(R.id.viewPager);
		tabs = (PagerSlidingTabStrip) view.findViewById(R.id.tabs);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		mActivity = (MainActivity) getActivity();
	}

	public String GetAreaCode(){
		return areaCode;
	}
	
	public void SetAreaCode(String areacode){
		this.areaCode=areacode;
	}
	
	public String GetWeek(){
		Log.e("", "GetWeek:"+week);
		return week;
	}
	
	public void SetWeek(String week){
		Log.e("", "SetWeek:"+week);
		this.week=week;
	}
	public class OfflineTabPageAdapter extends FragmentStatePagerAdapter {

		public OfflineTabPageAdapter(FragmentManager fm) {
			super(fm);
		}

		String pageTitle[] = { "Bài hát", "Album", "Video"};

		@Override
		public CharSequence getPageTitle(int position) {
			return pageTitle[position];
		}

		@Override
		public int getCount() {
			return pageTitle.length;
		}

		@Override
		public Fragment getItem(int i) {
			switch (i) {
			case 1:
				return BXHAlbumFragment.newInstance(BXHfragment.this);
			case 2:
				return BXHVideoFragment.newInstance(BXHfragment.this);
			default:
				return BXHSongFragment.newInstance(BXHfragment.this);
			}
		}
	}
}